class YxArea {
  var state_id ;
  var city_id = '';
  var area_id = '';
  var name = '';
  List<City> cityList;

  YxArea({this.state_id, this.name, this.cityList});

  YxArea.fromJson(Map<String, dynamic> json) {
    state_id = '${json['id']}';
    name = '${json['name']}';
    if (json['area'] != null) {
      cityList = new List<City>();
      json['area'].forEach((v) {
        cityList.add(new City.fromJson(v,state_id));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.state_id;
    data['name'] = this.name;
    if (this.cityList != null) {
      data['area'] = this.cityList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class City {
  String name;
  String state_id;
  String city_id;
  String area_id;
  List<Area> areaList;
  City({this.name, this.city_id,this.areaList});

  City.fromJson(Map<String, dynamic> json,String  father_id) {
    name = json['name'];
    city_id = '${json['id']}';
    state_id = father_id;
    if (json['area'] != null) {
      areaList = new List<Area>();
      json['area'].forEach((v) {
        areaList.add(new Area.fromJson(v,city_id,state_id));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['id'] = this.city_id;
    if (this.areaList != null) {
      data['area'] = this.areaList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Area {
  String name;
  String state_id;
  String city_id;
  String area_id;

  Area({this.name, this.area_id});

  Area.fromJson(Map<String, dynamic> json,String  father_id ,String grandfather_id) {
    state_id = grandfather_id;
    city_id = father_id;
    name = json['name'];
    area_id = '${json['id']}';
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['id'] = this.area_id;
    return data;
  }
}



enum YXAreaType {
  stateType,
  cityType,
  areaType,
}
class YXArea {


  var state_id = '';
  var city_id = '';
  var area_id = '';

  var state_name = '';
  var city_name = '';
  var area_name = '';

  var name = '';
  var YXArea_id = '' ;
  YXAreaType   areaType;
  List<YXArea> areaList;
  YXAreaType   childAreaType;


  YXArea({this.YXArea_id, this.name, this.areaList,this.areaType});

  YXArea.fromJson(Map<String, dynamic> json,YXArea  father_Area ,YXAreaType type) {
    YXArea_id = '${json['id']}';
    name = '${json['name']}';
    areaType =  type;

    if(type == YXAreaType.stateType || type == null){
      state_id = YXArea_id;
      state_name = name;
      childAreaType =  YXAreaType.cityType;
    }else if(type == YXAreaType.cityType && father_Area != null){
          state_id = father_Area.state_id;
          city_id = YXArea_id;

          state_name = father_Area.state_name;
          city_name = name;

          childAreaType =  YXAreaType.areaType;
    }else if(type == YXAreaType.areaType && father_Area != null){
          state_id = father_Area.state_id;
          city_id = father_Area.city_id;
          area_id = name;

          state_name = father_Area.state_name;
          city_name = father_Area.city_name;
          area_name = name;

          childAreaType =  YXAreaType.areaType;
    }
    if (json['area'] != null) {
      areaList = new List<YXArea>();
      json['area'].forEach((v) {
        areaList.add(new YXArea.fromJson(v,this,this.childAreaType));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.state_id;
    data['name'] = this.name;
    if (this.areaList != null) {
      data['area'] = this.areaList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}